<template>
	<div class="conMain">
		<el-card class="box-card">
			<div slot="header" class="topfix">
				<el-form :inline="true" :model="params" size="small" class="goodsForm" label-width="100px">
					<el-form-item label="员工ID">
						<el-input clearable v-model="params.s_admin_id" placeholder="请输入员工ID" />
					</el-form-item>
					<el-form-item label="姓名">
						<el-input clearable v-model="params['s_admin*nickname']" placeholder="请输入姓名" />
					</el-form-item>
					<el-form-item label="订单ID">
						<el-input clearable v-model="params.s_oid" placeholder="请输入订单ID" />
					</el-form-item>


					<el-form-item label="创建时间" prop="s_createtime">
						<el-date-picker v-model="params.s_createtime" type="daterange" value-format="yyyy-MM-dd"
							range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" />
					</el-form-item>
					<el-form-item label="备注">
						<el-input clearable v-model="params.s_more" placeholder="请输入备注" />
					</el-form-item>
					<el-form-item label=" ">
						<el-button type="primary" size="small" class="searchBtn" @click="handleSearch"
							icon='el-icon-search'>搜索</el-button>
						<el-button type="info" @click="handleRet" plain>清空</el-button>
					</el-form-item>
				</el-form>
				<div style="text-align: right;">
					<el-button v-has="'order/export'" type="primary" size="small" class="ml10" @click="down" plain><i
							class="el-icon-download" />导出</el-button>
				</div>
			</div>
			<el-table v-loading="loading" :data="list" style="width: 100%" :empty-text='emtypetxt'>
				<el-table-column prop="id" label="序号" align="center" width="100" />
				<el-table-column prop="admin_id" label="员工ID" align="center" width="100" />
				<el-table-column prop="admin.nickname" label="姓名" align="center" width="120"
					:show-overflow-tooltip="true" />
				<el-table-column prop="memo" label="类型" align="center" :show-overflow-tooltip="true" />
				<el-table-column prop="before" label="之前余额" align="center" width="100" />
				<el-table-column prop="money" label="变动金额" align="center" width="100" />
				<el-table-column prop="after" label="当前余额" align="center" width="100" />

				<el-table-column prop="oid" label="订单信息" align="center" :show-overflow-tooltip="true">
					<template slot-scope="scope">
						{{scope.row.oid?'ID：'+scope.row.oid:''}}{{scope.row.order.phone?'，订购号码：'+scope.row.order.phone:''}}
					</template>
				</el-table-column>

				<el-table-column prop="more" label="备注" align="center" width="180" :show-overflow-tooltip="true" />

				<el-table-column prop="createtime" label="创建时间" align="center" width="200" />
			</el-table>
			<div class="pagination">
				<el-pagination :current-page="params.page" :page-sizes="[10, 20, 50, 100]" :page-size="params.pagesize"
					layout="total, sizes, prev, pager, next, jumper" :total="total" @size-change="handleSizeChange"
					@current-change="handleCurrentChange" />
			</div>
		</el-card>
	</div>
</template>

<script>
	import {
		mlog_index,
		mlog_export,
		mlog_export_csv
	} from '@/api/admin'


	export default {
		data() {
			return {
				total: 0,
				loading: true,
				emtypetxt: '',
				list: [],
				params: {
					s_agent_id: '',
					's_agent*name': '',
					s_oid: '',
					s_more: '',
					s_createtime: [],
					'ss_agent*name': 'LIKE',
					ss_createtime: 'BETWEEN',
					ss_more: 'LIKE',
					page: 1,
					pagesize: 10,
				},


			}
		},
		created() {
			this.getList()
		},
		methods: {
			down() {
				const loading = this.$loading({
					lock: true,
					text: '正在导出...',
					spinner: 'el-icon-loading',
					background: 'rgba(20, 20, 20, 0.7)'
				})
				mlog_export_csv(this.params).then(res => {
					window.location.href = res.data.filename
					loading.close()
				})
				// mlog_export(this.params).then(res => {
				// 	if (res.msg != '') {
				// 		Message({
				// 			message: res.msg,
				// 			type: 'error',
				// 			duration: 2000
				// 		})
				// 	} else {
				// 		const {
				// 			export_json_to_excel
				// 		} = require('../../assets/js/Export2Excel')
				// 		const tHeader = res.data.header
				// 		const filterVal = res.data.filter
				// 		const list = res.data.list
				// 		const data = this.formatJson(filterVal, list)
				// 		export_json_to_excel(tHeader, data, res.data.ename)
						
				// 	}
				// 	loading.close()
				// })

			},
			formatJson(filterVal, jsonData) {
				return jsonData.map(v => filterVal.map(j => v[j]))
			},
			getList() {
				this.emtypetxt = '加载中...';
				this.loading = true;
				mlog_index(this.params).then(res => {
					this.list = res.data.list
					this.total = res.data.total
					this.loading = false
					if (this.list.length == 0) {
						this.emtypetxt = '暂无数据'
					}
				})
			},
			handleSearch() {
				this.list = [];
				this.params.page = 1;
				this.getList()
			},
			//分页
			handleSizeChange(val) {
				this.params.pagesize = val
				this.getList()
			},
			handleCurrentChange(val) {
				this.params.page = val
				this.getList()
			},
			handleRet() {
				this.params = {
					s_agent_id: '',
					's_agent*name': '',
					s_oid: '',
					s_more: '',
					s_createtime: [],
					'ss_agent*name': 'LIKE',
					ss_createtime: 'BETWEEN',
					ss_more: 'LIKE',
					page: 1,
					pagesize: 10,
				}
				this.getList()
			},


		},
	}
</script>

<style lang="scss" scoped>


</style>